package com.sx.micowell.framework.tools.cmd;

import com.sx.micowell.framework.tools.CacheUtils;
import com.sx.micowell.framework.tools.CalcuUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Author 梁浩文
 * @Date 2021/9/16 9:24
 */
public class CmdUntil {
    public static final double space = 0.01;

    public static final double calories = 0.2389;

    /**
     * @param power
     * @return 计算卡路里
     */
    public static BigDecimal countCalories(int power) {
        BigDecimal mul = CalcuUtils.getInstance().mul(new BigDecimal(space), new BigDecimal(calories), 5);
        BigDecimal tempCalories = CalcuUtils.getInstance().mul(new BigDecimal(power), mul, 2);
        return tempCalories;
    }

    public static List<CmdException> getCmdExceptionList(Integer value) {
        Integer[] byteMove = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02,0x01};
        String[][] names = {{"电机已校准", "电机未校准"}, {"速度未超标", "速度超标"}, {"位置在允许范围内", "位置在允许范围外"},
                {"板子温度正常", "板子温度超标"}, {"温度正常", "温度超标"}, {"泄放功能正常", "泄放功能异常"},
                {"母线电压正常", "母线电压异常"},{"插销正常","插销被拔出"}};
        List<CmdException> cmdExceptions = new ArrayList<>();
        for (int i = 0; i < byteMove.length; i++) {
            CmdException cmdException = new CmdException();

            int move = value & byteMove[i];
            String name;
            if (move != 0) {
                //异常
                cmdException.error = true;
                name = names[i][1];
            } else {
                cmdException.error = false;
                name = names[i][0];
            }
            cmdException.name = name;
            cmdException.id = i;
            cmdExceptions.add(cmdException);
        }
        return cmdExceptions;
    }


}
